/*
 *   Copyright 2021 zzh
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */

package com.aduib.boot.common.buffer;

import java.util.concurrent.ConcurrentMap;

/**
 * @description: BufferPool
 * @author: zzh
 * @date: 2021/12/1 14:36
 */
public interface BufferPool {
  /**
   * 申请buffer
   *
   * @param size
   * @return
   */
  Buffer allocate(int size);

  /**
   * 返回池化buffer
   *
   * @param cache
   * @param reqCapacity
   * @param maxCapacity
   * @return
   */
  Buffer allocate(PoolThreadCache cache, int reqCapacity, int maxCapacity);

  /**
   * 申请大buffer
   *
   * @return
   */
  BigBuffer allocateBig();

  /**
   * 申请指定大小的大buffer
   *
   * @param reqCapacity
   * @return
   */
  BigBuffer allocateBig(int reqCapacity);

  /**
   * 回收buffer
   *
   * @param theBuf
   */
  void recycle(Buffer theBuf);

  /**
   * 回收池化buffer
   *
   * @param cache
   * @param theBuf
   */
  void recycle(PoolThreadCache cache, Buffer theBuf);

  /**
   * 容量
   *
   * @return
   */
  long capacity();

  /**
   * 数据长度
   *
   * @return
   */
  long size();

  int getConReadBufferChunk();

  int getSharedOptsCount();

  int getChunkSize();

  int getPageSize();

  ConcurrentMap<Long, Long> getNetDirectMemoryUsage();
}
